<template>
	<view>
		
		<view class="user-info-box">
		  <navigator url="/pages/person/info" class="user-info">
		    <view class="info-hd" :model="user">
		      <image class="user-avatar" :src="user.avatar"></image>
		      <view class="user-title">
				<text class="user-name">学院：{{user.college}}</text>
				<text class="user-name">班别：{{user.classname}}</text>
		        <text class="user-name">名字：{{user.name}}</text>
				<text class="user-name">学号：{{user.sid}}</text>
		      </view>
		    </view>
		  </navigator>
		</view>
		<!-- 申请记录 -->
		<view style="margin:0 17px ;">
			<button class="apply_btn" type="primary" @tap="goApply()">申请</button>
		</view>
		<view class="part">
			<view class="txt">有效出入证</view>
		</view>

		<view class="applay-info-box"  >
			<view class="nav_item"  v-for="(item,index) in applyList" :key="index">
				<view class="applay-info" v-if="item.state==1 && Date.parse(item.endTime)>new Date()" @click="goAppling(item.id)">
					<view class="info-hd">
					  <view class="user-title" >
						<view>
							<text class="applay1">{{item.accessType}}</text>
						</view>
						<view>
							<text class="applay1">花都赤坭校区-学校正门</text>
						</view>
						<view>
							<text class="applay11">权限有效时间：{{item.startTime}}---{{item.endTime}}</text>
						</view>
						<view>
							<text class="applay11">申请时间：{{item.startTime}}</text>
						</view>
						<view>
							<text class="applay11">申请原因：{{item.reason}}</text>
						</view>
					  </view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user:{
					name:"",
					sid:"",
					college:"",
					classname:"",
					avatar:'',
				},
				applyList:[],
				sid:"",
				id:""
			}
		},
		created() {
			this.sid=uni.getStorageSync("userinfo").sid
			console.log(this.sid)
			this.getApllyList(this.sid)
			this.user.name=uni.getStorageSync("userinfo").username
			this.user.sid=uni.getStorageSync("userinfo").sid
			this.user.classname=uni.getStorageSync("userinfo").classname
			this.user.avatar=uni.getStorageSync("userinfo").avatar
			this.user.college=uni.getStorageSync("userinfo").college
		},
		methods: {
			// 获取用户申请记录
			getApllyList(sid){
				uni.request({
					url: `http://localhost:8090/leave/info`,
					method: 'GET',
					data:{sid:sid},
					success: (res) => {
						console.log("申请请假信息：",res);
						this.applyList = res.data.data
					},
					fail:(res)=> {
						console.log("失败",res);
					},	
				});
			},
			goAppling(id) {
				uni.navigateTo({
					url: '../apply/appling?id='+id
			
				})
			},
			// 进入申请页
			goApply(){
				uni.showToast({
					title:"正在进入申请页...",
					icon:'loading',
					duration:3000,
					success: () => {
						console.log("调用成功");
						setTimeout(()=>{
							uni.navigateTo({
								url:"../apply/apply"
							})
						}
						,1000)
					},
					fail: () => {
						console.log("调用失败");
					},
					complete(){
						console.log("完成调用");
					}
				})
			},

		}
	}
</script>

<style>
.user-info-box{
  margin-bottom: 30rpx;
  margin: 30rpx;
}
.user-info {
  display: flex;
  background-color: #fff;
  min-height: 85rpx;
  border: 2px solid #5dabfd;
  flex-direction: column;
  padding: 25rpx 30rpx 20rpx;
}
.part{
	text-align: center;
	margin: 20px;
	flex-direction: row;
	/* height: 50px; */
	border-radius: 25px;
	border-top: 1rpx solid #949494;
}
.txt{
	color: #4811ff;
	margin-top: 10px;
	font-weight: 700;
	text-align: center;
	font-size: 20pt;
	font-family: "幼圆";
}
.info-hd {
  display: flex;
  align-items: center;
}
.user-avatar {
  width: 300rpx;
  height: 300rpx;
  border-radius: 5px;
}
.user-title {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding-left: 25rpx;
}
.user-name {
  font-size: 14pt;
  margin-top: 10px;
  line-height: 160%;
  font-weight: 600;
  font-family: "幼圆";
  letter-spacing: 1px;
}
.applay-info-box{
	margin: 35rpx;
}
.applay1{
	font-size: 12pt;
	font-weight: 700;
}
.applay2{
	font-size: 12pt;
	margin-left: 35px;
	font-weight: 700;
}
.applay3{
	margin-left: 35px;
	font-size: 12pt;
	font-weight: 700;
	color: #4811ff;
}
.applay11{
	font-size: 10pt;
	font-weight: 700;
	color: #b9b8be;
	margin-right: 35px;
}
.applay-info{
	margin-top: 30rpx;
	display: flex;
	background-color: #fff;
	min-height: 85rpx;
	border: 1px solid #b9b8be;
	flex-direction: column;
	padding: 35rpx 30rpx 25rpx;
}
</style>
